package com.zabra.zl.ui.verifyperson.presenter;

import com.zabra.zl.base.BasePresenter;
import com.zabra.zl.data.VerifyPersonBean;
import com.zabra.zl.ui.verifyperson.contract.VerifyPersonContract;
import com.zabra.zl.ui.verifyperson.model.VerifyPersonModel;

import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class VerifyPersonPresenter extends BasePresenter<VerifyPersonContract.View> implements VerifyPersonContract.Presenter {
    private VerifyPersonContract.Model model;

    public VerifyPersonPresenter() {
        model = new VerifyPersonModel();
    }

    @Override
    public void getUserInfo(RequestBody body) {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getUserInfo(body).enqueue(new Callback<VerifyPersonBean>() {
            @Override
            public void onResponse(Call<VerifyPersonBean> call, Response<VerifyPersonBean> response) {
                mView.hideLoading();
                mView.onSuccess(response.body(), response.headers().get("token"));
            }

            @Override
            public void onFailure(Call<VerifyPersonBean> call, Throwable t) {
                mView.hideLoading();
                mView.onError(t);
            }
        });
    }
}
